package com.payment.ktb.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.payment.ktb.R;
import com.payment.ktb.model.AgentMsgEntity;
import com.payment.ktb.model.BankType;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by admin on 2017/9/29.
 */

public class AgentMsgAdapter extends BaseAdapter {


    Context mContext;
    List<AgentMsgEntity> listDatas;


    public AgentMsgAdapter() {
    }

    public AgentMsgAdapter(Context mContext, List<AgentMsgEntity> listDatas) {
        this.mContext = mContext;
        this.listDatas = listDatas;
    }

    @Override
    public int getCount() {
        return listDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return listDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = View.inflate(mContext, R.layout.adapter_agentmsg_item,null);
            viewHolder.iv_agentmsg_header = (ImageView) view.findViewById(R.id.iv_agentmsg_header);
            viewHolder.tv_agentmsg_title = (TextView) view.findViewById(R.id.tv_agentmsg_title);
            viewHolder.tv_agentmsg_time = (TextView) view.findViewById(R.id.tv_agentmsg_time);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        if (!TextUtils.isEmpty(listDatas.get(i).getNoticeIcon())) {
            Picasso.with(mContext).load(listDatas.get(i).getNoticeIcon()).fit().into(viewHolder.iv_agentmsg_header);
        }else if (listDatas.get(i).getNoticeType() == 1) {
            //申请成为代理商
            Picasso.with(mContext).load(R.mipmap.message_notice).fit().into(viewHolder.iv_agentmsg_header);
        }else {
            //已经成为代理商
            Picasso.with(mContext).load(R.mipmap.my_head_portrait).fit().into(viewHolder.iv_agentmsg_header);
        }
        viewHolder.tv_agentmsg_title.setText(listDatas.get(i).getNoticeTitle());
        viewHolder.tv_agentmsg_time.setText(listDatas.get(i).getNoticeTime());

        return view;
    }



    class ViewHolder {
        ImageView iv_agentmsg_header;
        TextView tv_agentmsg_title;
        TextView tv_agentmsg_time;
    }


}
